import request from "@/utils/request"

import request2 from "@/utils/request2";
export async function queryGoodsList(data: Goods.QueryListParams) {
  return request2<Goods.Entity[]>(`/api/mall/manage/goods/${data.pageSize}/${data.pageNum}`, {
    method: 'GET',
    data: {...data, pageSize: undefined, pageNum: undefined},
  })
}

export async function delGoods(data: {goodsId: string}) {
  return request2(`/api/mall/manage/goods/${data.goodsId}`, {
    method: 'DELETE',
  })
}

export async function saveGoods(data: Partial<Goods.Entity>) {
  return request2(`/api/mall/manage/goods`, {
    method: 'POST',
    data: data,
  })
}

export async function saveGoodsSku(data: {sku: Partial<Goods.Sku>[]}) {
  return request2<Goods.Sku[]>(`/api/mall/manage/goods/sku`, {
    method: 'POST',
    data: data,
  })
}

export async function queyGoodsDetail(data: {id: string}) {
  return request2<Goods.Entity>(`/api/mall/manage/goods/${data.id}`, {
    method: 'GET',
  })
}

export async function queyGoodsOrderList(data: Goods.QueryGoodsOrderParams) {
  return request2<Goods.Order[]>(`/api/mall/manage/order/${data.pageSize}/${data.pageNum}`, {
    method: 'POST',
    data: {...data, pageSize: undefined, pageNum: undefined},
  })
}

export async function deliverGoodsOrder(data: {orderId: string, companyCode: string, logistics: string}) {
  return request2(`/api/mall/manage/order/deliver/${data.orderId}/${data.logistics}/${data.companyCode}`, {
    method: 'PUT',
    data: {...data, orderId: undefined},
  })
}

export async function getLogisticsData(data: {orderId: string, logistics: string}) {
  return request2<any>(`/api/mall/order/${data.orderId}/${data.logistics}`, {
    method: 'POST',
    data: {...data, orderId: undefined},
  })
}

export async function getGoodsOrderDetail(data: {orderId: string}) {
  return request2<Goods.Order>(`/api/mall/manage/order/detail/${data.orderId}`, {
    method: 'GET',
  })
}

export async function getGoodsCouponList(data: Goods.QueryGoodsCouponParams) {
  return request<Goods.MallCoupon[]>(`/api/mall/manage/coupon/${data.pageSize}/${data.pageNum}`, {
    method: 'POST',
    data: {...data, pageSize: undefined, pageNum: undefined},
  })
}

export async function saveGoodsCoupon(data: Partial<Goods.MallCoupon>) {
  return request2(`/api/mall/manage/coupon`, {
    method: 'POST',
    data,
  })
}

export async function getGoodsCoupon(id: string) {
  return request2(`/api/mall/coupon/detail`, {
    method: 'GET',
    data: {couponId: id}
  })
}

export async function delGoodsCoupon(data: Partial<Goods.MallCoupon>) {
  return request2(`/api/mall/manage/coupon/${data.couponId}`, {
    method: 'DELETE',
  })
}

export async function getDrawRecord(data: PaginationParams & {couponId?: string, draw?: boolean}) {
  return request2<Goods.MallCouponDrawRecord[]>(`/api/mall/manage/coupon/${data.pageSize}/${data.pageNum}/${data.couponId}`, {
    method: 'GET',
    data: {
      draw: data.draw,
    }
  })
}

export async function queryPointsGoodsList(data: Goods.QueryPointsGoodsListParams) {
  return request2<Goods.PointsGoods[]>(`/api/mall/manage/goods/integral/${data.pageSize}/${data.pageNum}`, {
    method: 'GET',
    data: {...data, pageNum: undefined, pageSize: undefined},
  })
}

export async function delPointsGoodsBatch(data: {ids: string[]}) {
  return request2(`/api/mall/manage/goods/integral/del`, {
    method: 'POST',
    data,
  })
}

export async function savePointsGoodsBatch(data: {reqList: Partial<Goods.PointsGoods>[]}) {
  return request2(`/api/mall/manage/goods/integral`, {
    method: 'POST',
    data,
  })
}

export async function saveConfig(params: {id?: string, goodsIds?: string, couponId: string, otherCfg: string}) {
  return request2(`/api/mall/manage/goods/invite/goods/cfg`, {
    method: 'POST',
    data: params,
  })
}

export async function getConfig() {
  return request2<{id: string, goodsIds: string, couponId: string, list: Goods.Entity[], couponRes: any, otherCfg: string}>(`/api/mall/manage/goods/invite/goods/cfg`, {
    method: 'GET',
  })
}

export async function generateCouponCode(params: {couponId: string, num: number}) {
  return request2(`/api/mall/manage/coupon/generate/${params.couponId}/${params.num}`, {
    method: 'POST',
  })
}
